package com.madder.myharmonos.controller;

import com.madder.myharmonos.mapper.DogMapper;
import com.madder.myharmonos.entity.Dog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class DogController {

    @Autowired
    private DogMapper dogMapper;

     @RequestMapping(value = "dogs",
     method = RequestMethod.GET)
    public List<Dog> getDog() {
        // http:/127.0.0.1:8080/v1/dogs
        return dogMapper.getAllDog();
    }

    //根据id查询
    @GetMapping("/dogs/{id}")
    public Dog getDogById(@PathVariable("id") Integer id) {
        // http:/127.0.0.1:8080/v1/dogs/1
         Dog dog = dogMapper.getDogById(id);
         return dog;
    }

    //添加
    @PostMapping("/dogs")
    public boolean addDog(@RequestBody Dog dog) {
        // http:/127.0.0.1:8080/v1/dogs
         return dogMapper.addDog(dog);
    }

    //删除
    @DeleteMapping("/dogs/{id}")
    public boolean deleteDog(@PathVariable("id") Integer id) {
        // http:/127.0.0.1:8080/v1/dogs/91
         return dogMapper.deleteDogById(id);
    }

    //修改
//    @PutMapping("/dogs/{id}")
//    public boolean updateDog(@PathVariable("id") Integer id,
//                             @RequestParam("name") String name,
//                             @RequestParam("age") Integer age) {
//
//        Dog dog = new Dog();
//        dog.setName(name);
//        dog.setAge(age);
//         return dogMapper.updateDog(dog);
//    }
}
